import com.wanxi.domain.code.ResultCode;
import com.wanxi.domain.dto.OrderStatus;
import com.wanxi.domain.vo.OrderProductVO;
import com.wanxi.domain.vo.OrderQueryVO;
import com.wanxi.domain.vo.OrderVO;
import com.wanxi.domain.vo.PlaceOrderVO;
import com.wanxi.order.OrderApplication;

import com.wanxi.order.service.OrderService;
import com.wanxi.order.service.impl.OrderServiceImpl;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

/**
 * @Author LiuYuRong
 * @Date 2022/1/4 15:39
 * @Version 1.0
 * @Description
 */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = OrderApplication.class)
public class OrderApplication1 {
    @Autowired
    private OrderService orderService;

    //    门店查询自己的订单
    @Test
    public void SelectOrdersTest() {
        System.out.println("门店订单");
        OrderQueryVO vo = new OrderQueryVO();
//        vo.setAmountBottom(100.0);
//        vo.setAmountTop(200.0);
//        vo.setUsername("浩二");
        vo.setPage(1);
        vo.setPageSize(10);
//        vo.setCouponType("1");
        List<OrderVO> orders = orderService.getOrders(1, 1, vo);
        System.out.println(orders);
    }


//    用户查询自己的订单

    @Test
    public void selectOrderByUserId() {
        System.out.println("用户订单");
        OrderQueryVO vo = new OrderQueryVO();
        vo.setPage(2);
        vo.setPageSize(10);
        orderService.getOrders(1, 0, vo);
    }

    //    企业查询自己的订单
    @Test
    public void selectOrderByEid() {
        System.out.println("企业订单");
        OrderQueryVO vo = new OrderQueryVO();
        vo.setPage(1);
        vo.setPageSize(10);
        orderService.getOrders(9, 2, vo);
    }


    //    下订单
    @Test
    public void addOrdersTest() {
        System.out.println("下单");


        PlaceOrderVO placeOrderVO = new PlaceOrderVO();
        System.out.println("输入地址");

        placeOrderVO.setAddress("米奇妙妙屋");
        System.out.println("输入优惠劵id");

        placeOrderVO.setCouponId(2L);
        System.out.println("输入手机号");

        placeOrderVO.setPhone("123544444");

        System.out.println("输入用户id");

        placeOrderVO.setUserId(2L);
        List<OrderProductVO> list = new ArrayList<>();

        System.out.println("分别输入skuid，商品数量，店铺id");
        list.add(new OrderProductVO(1, 2, 1));
        list.add(new OrderProductVO(2, 4, 2));
        list.add(new OrderProductVO(3, 6, 3));
        list.add(new OrderProductVO(6, 9, 4));
        list.add(new OrderProductVO(6, 10, 5));
        list.add(new OrderProductVO(6, 10, 6));
        placeOrderVO.setProductVOS(list);
        int i = orderService.addOrder(placeOrderVO);
        System.out.println(i);
    }


//    发货

    @Test
    public void SendTest() {
        System.out.println("发货");
        ResultCode resultCode = orderService.changeOrderStatus(42, OrderStatus.send);
        System.out.println(resultCode);
    }

    //  收货
    @Test
    public void ReceiverTest() {
        System.out.println("收货");
        ResultCode resultCode = orderService.changeOrderStatus(42, OrderStatus.received);
        System.out.println(resultCode);
    }

    //    自动取消
    @Test
    public void AutoCancel() {
        System.out.println("自动取消");
        ResultCode resultCode = orderService.changeOrderStatus(41, OrderStatus.autoCanceled);
        System.out.println(resultCode);
    }

    //    手动取消
    @Test
    public void handleCancel() {

        ResultCode resultCode = orderService.changeOrderStatus(40, OrderStatus.handleCanceled);

    }


    //删除订单
    @Test
    public void deleteOrderByIdTest() {

            ResultCode resultCode = orderService.deleteOrder(40L);

    }

    //    支付订单
    @Test
    public void payOrder() {
        int i = orderService.payOrder(4);
        System.out.println(i);
    }


    //    订单前数据计算
    @Test
    public void testBeforeSubmitOrder() {

        PlaceOrderVO placeOrderVO = new PlaceOrderVO();
        List<OrderProductVO> list = new ArrayList<>();
        list.add(new OrderProductVO(1, 2, 1));
        list.add(new OrderProductVO(2, 4, 2));
        list.add(new OrderProductVO(3, 6, 3));
        list.add(new OrderProductVO(6, 9, 2));
        list.add(new OrderProductVO(6, 10, 1));
        list.add(new OrderProductVO(6, 10, 1));

        placeOrderVO.setProductVOS(list);
//        placeOrderVO.setCouponId(4L);
//        placeOrderVO.setCouponId(5L);
        Map<String, Object> map = orderService.beforeSubmitOrder(placeOrderVO);
        System.out.println(map);

    }


}
